package com.codedef.controller;

import com.codedef.common.response.Result;
import com.codedef.entity.Classroom;
import com.codedef.fservice.TestFeign;
import com.codedef.service.ClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/classroom")
public class ClassroomController {

    @Autowired
    ClassroomService classroomService;

    @Autowired
    TestFeign testFeign;

    @GetMapping("/classroomtest")
    public String test() {
        return "woc" + testFeign.test().toString();
    }

    /**
     * 获得所有的自习室
     */
    @GetMapping("/all")
    public Result getAll() {
        return Result.SUCCESS(classroomService.getAllClassroom());
    }

    /**
     * 通过Floor id获得自习室
     */
    @GetMapping("/{id}")
    public Result getClassroomByFloorId(@PathVariable("id") Integer floorId) {
        return Result.SUCCESS(classroomService.getAllClassroomListByFloorId(floorId));
    }

    /* ----------------------------------------- Feign ----------------------------------------- */
    /**
     * 获得所有的自习室 Feign接口
     */
    @GetMapping("/f/all")
    public List<Classroom> getAllFeign() {
        System.out.println("getAllFeign被调用");
        return classroomService.getAllClassroom();
    }

}
